#ifndef MOVEABLEFRAMELESSWINDOW_H
#define MOVEABLEFRAMELESSWINDOW_H

#include <QObject>
#include <QWidget>
#include <QPoint>
#include <wsim/websocket_common.h>
#include "chatform.h"
#include "litteriem.h"
#include "../service/wsim.h"
#include "../wsim_client.h"

class clientItem
{
public:
    clientItem() {}
    int fd;
    QString uuid;
    QString nickname;
    QString mood;
    QString organ;
    QString group;
    bool breg;
    LitterIem* litter;
    chatForm* talkwnd;
};
class WS_MESSAGE
{
public:
    int f_fd;
    QString f_nickname;
    QString f_uuid;
    QString message;
};
/**
 * @brief 无边框窗体
 */
class MoveableFramelessWindow : public QWidget
{
    Q_OBJECT
public:
    explicit MoveableFramelessWindow(QWidget *parent);
    bool event(QEvent* e);

    int callCloseed(int fd);
    int callBack(int fd, WebsocketData_Type datatype, char *buf, unsigned int bufLen);
private:
protected:
    /**
     * @brief 鼠标按下，准备拖动窗体
     * @param event
     */
    void mousePressEvent(QMouseEvent *event);

    /**
    * @brief 鼠标移动，处理窗体拖动
    * @param event
    */
   void mouseMoveEvent(QMouseEvent *event);

   /**
    * @brief 释放鼠标
    * @param event
    */
   void mouseReleaseEvent(QMouseEvent *event);


    /**
     * @brief 获取可拖动控件，必须由子类指定
     * @return
     */
    virtual QWidget*getDragnWidget()=0;

    /**
     * @brief 判断鼠标点击的位置是否进入可拖动区域
     * @param widget 可拖动控件位置
     * @param point  鼠标点击位置
     * @return
     */
     bool isPointInDragnWidget(const QWidget*widget,const QPoint &point);

     /**
      * @brief 标志是否移动窗体
      */
     bool isMove;

     /**
       * @brief 鼠标按下去的点
       */
      QPoint pressedPoint;

      virtual void onCloseWS(){}

      int wsfd;
      int server_fd;//本客户在服务器服fd;
      std::string server_uuid;//本客户在服务器UUID;
      std::string server_nickname;
      std::string server_organ;
      std::string server_name;
      std::string server_mobileNumber;
      std::string server_group;
protected slots:
     //主题改变
     virtual void onThemeColorChange(QString colorStr){}
signals:

public slots:
protected slots:
      virtual void slotAddClient(clientItem,int){};//客户添加槽
      virtual void slotDropClient(clientItem){}
      virtual void slotMessage(WS_MESSAGE){};
      virtual void slot_wsFile(wsimBIN_head){};
      virtual void slot_wsRequest(int,int,QString,linkItem){};
      virtual void slot_wsTransfer(int ,int , int ,int ){};

      virtual void slot_wsTeamTransfer(int ,int ,int,int ,QByteArray ){};
      virtual void slot_wsTeamClose(int,int,int){};
      virtual void slot_wsTeamCommand(int,int,int,QString){};

 signals:
    void explains();//必须
    void sigAddClient(clientItem item,int t);//客户添加信号
    void sigDropClient(clientItem item);//
    void sigMessage(WS_MESSAGE msg);
    void sig_wsFile(wsimBIN_head head);
    void sig_wsTransfer(int tfd,int ffd, int magic,int index);
    void sig_wsRequest(int ffd,int magic,QString request,linkItem questItem);

    void sig_wsTeamTransfer(int tfd,int ffd,int magic,int index,QByteArray barray);//远程协程接收桌面
    void sig_wsTeamClose(int tfd,int ffd,int magic);//协助接收关闭

    void sig_wsTeamCommand(int tfd,int ffd,int magic,QString command);//协助指令
};
Q_DECLARE_METATYPE(clientItem)

#endif // MOVEABLEFRAMELESSWINDOW_H
